const shotModel = require("../model/shotModel");

module.exports.find = async function (params, pagination) {
    let { current, pageSize } = pagination;

    let total = await shotModel.countDocuments(params);

    let data = await shotModel.find(params).limit(pageSize).skip((current - 1) * pageSize);
    return {
        current, pageSize, total, rows: data
    }
}

module.exports.findAll = async function () {
    return await shotModel.find();
}

module.exports.insert = async function (params) {
    console.log(params);
    return await shotModel.create(params);
}

module.exports.findById = async function (id) {
    return await shotModel.findById(id);
}

module.exports.update = async function (params) {
    return await shotModel.updateOne({ _id: params.id }, params);
}

module.exports.remove = async function (id) {
    return await shotModel.deleteOne({ _id: id });
}